<?php
ob_start();
session_start();
?>
<html>
<head>
	<link href="inc/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<?php
	include('inc/config.php');
	$random = rand(111111,999999);
	$css = "hidden";
?>
<?php
	if (isset($_POST['submitted']))
	{
		if (!empty($_POST['introducido']))
		{
			$random = $_POST['randomant'];
			$introducido = $_POST['introducido'];
			$acceso = $random%$secretcode;
			
			if ($introducido == $acceso)
			{
				$_SESSION['validate'] = 1; //si acierta el code, inicializamos la sesion a 1.
				header('Location: index.php');
			}
			else
			{
				$css = "visible";
				$random = rand(111111,999999);
			}
		}
		else
		{
			$css = "visible";
		}
	}
?>
<form action="" method="post" name="formLogin" class="formLogin">
	<input type="hidden" name="submitted" value="true">
  <input type="hidden" name="randomant" value="<?php echo $random; ?>"></br>
	 
	<div id='logoff' style='visibility:<?php echo $css; ?>'><center>Login failed!</center></div>
		<fieldset>
			<legend>Project Marks</legend>
			<p>
				<label for="username">Code:</label>
           <label for="cod"><?php echo $random; ?></label></br></br>
			</p>
			<p>
				<label for="password">Password:</label>
				<input type="password" id="password" name="introducido" tabindex="2" title="password" />
			</p>
			<p>
				<input type="submit" value="Accept" id="submit" class="button" tabindex="3" />
			</p>
		</fieldset>
</form>

</body>
</html>
<?php
ob_end_flush();
?>